<?php
declare(strict_types=1);
 

namespace App\Fastapp\Mapper;

use App\Fastapp\Model\AccountRecharge;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 充值列表Mapper类
 */
class FastappAccountRechargeMapper extends AbstractMapper
{
    /**
     * @var AccountRecharge
     */
    public $model;

    public function assignModel()
    {
        $this->model = AccountRecharge::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        // 用户id
        if (isset($params['user_id']) && filled($params['user_id'])) {
            $query->where('user_id', '=', $params['user_id']);
        }

        // 币种
        if (isset($params['symbol']) && filled($params['symbol'])) {
            $query->where('symbol', '=', $params['symbol']);
        }

        // 交易单号
        if (isset($params['trade_no']) && filled($params['trade_no'])) {
            $query->where('trade_no', '=', $params['trade_no']);
        }

        return $query->orderByDesc('id');
    }
}